package com.ruoyi.web.controller.asset;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.DisposalRecord;
import com.ruoyi.asset.service.IDisposalRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报废处理记录Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@Controller
@Api("报废记录管理")
@RequestMapping("/asset/dsiposalRecord")
public class DisposalRecordController extends BaseController {
    private String prefix = "asset/dsiposalRecord";

    @Autowired
    private IDisposalRecordService disposalRecordService;

    @RequiresPermissions("asset:dsiposalRecord:view")
    @GetMapping()
    public String dsiposalRecord() {
        return prefix + "/dsiposalRecord";
    }

    /**
     * 查询报废处理记录列表
     */
    @RequiresPermissions("asset:dsiposalRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DisposalRecord disposalRecord) {
        startPage();
        List<DisposalRecord> list = disposalRecordService.selectDisposalRecordList(disposalRecord);
        return getDataTable(list);
    }

    /**
     * 导出报废处理记录列表
     */
    @RequiresPermissions("asset:dsiposalRecord:export")
    @Log(title = "报废处理记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DisposalRecord disposalRecord) {
        List<DisposalRecord> list = disposalRecordService.selectDisposalRecordList(disposalRecord);
        ExcelUtil<DisposalRecord> util = new ExcelUtil<DisposalRecord>(DisposalRecord.class);
        return util.exportExcel(list, "报废处理记录数据");
    }

    /**
     * 新增报废处理记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存报废处理记录
     */
    @RequiresPermissions("asset:dsiposalRecord:add")
    @Log(title = "报废处理记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DisposalRecord disposalRecord) {
        return toAjax(disposalRecordService.insertDisposalRecord(disposalRecord));
    }

    /**
     * 修改报废处理记录
     */
    @RequiresPermissions("asset:dsiposalRecord:edit")
    @GetMapping("/edit/{disposalId}")
    public String edit(@PathVariable("disposalId") String disposalId, ModelMap mmap) {
        DisposalRecord disposalRecord = disposalRecordService.selectDisposalRecordByDisposalId(disposalId);
        mmap.put("disposalRecord", disposalRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存报废处理记录
     */
    @RequiresPermissions("asset:dsiposalRecord:edit")
    @Log(title = "报废处理记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DisposalRecord disposalRecord) {
        return toAjax(disposalRecordService.updateDisposalRecord(disposalRecord));
    }

    /**
     * 删除报废处理记录
     */
    @RequiresPermissions("asset:dsiposalRecord:remove")
    @Log(title = "报废处理记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(disposalRecordService.deleteDisposalRecordByDisposalIds(ids));
    }


    @RequiresPermissions("asset:dsiposalRecord:statement")
    @GetMapping("/disposalStatement")
    public String disposalStatement() {
        return prefix + "/disposalStatement";
    }


    @PostMapping("/rest/disposal")
    @ApiOperation("增加报废接口")
    public AjaxResult disposal(DisposalRecord disposalRecord) {


        String disposal = disposalRecordService.disposal(disposalRecord);
        return StringUtils.isEmpty(disposal) ? new AjaxResult(AjaxResult.Type.SUCCESS, "报废成功") : new AjaxResult(AjaxResult.Type.ERROR, disposal);
    }


//    @RequiresPermissions("asset:dsiposalRecord:statementList")
//    @PostMapping("/disposalStatement")
//    @ResponseBody
//    public AjaxResult disposalStatementList() {
//        return toAjax(1);
//    }
}
